<?php

/**
 * Description of Helper
 *
 * @author suman
 */

class Helper {    
    public $base_url;
    public $theme_url;
    public $css_url;
    public $images_url;
    public $js_url;
    
    function __construct() {
        if(empty($this->base_url)){
            $this->base_url();
        }
        if(empty($this->theme_url)){
            $this->theme_url();
        }
        if(empty($this->js_url)){
            $this->js_url();
        }
        if(empty($this->css_url)){
            $this->css_url();
        }
        if(empty($this->images_url)){
            $this->images_url();
        }
    }

    public function base_url(){
        if(!empty($this->base_url)){
            return $this->base_url;
        }
        $config = $this->loadConfig('config.php');        
        $this->base_url = $config['base_url'];
        if($config['base_url']=="" || empty($config)){
            $port = "";
            $base_url = "http://";
            if($_SERVER['SERVER_PORT']==443){
                $base_url = "https://";
            }elseif ($_SERVER['SERVER_PORT']!=80) {
                $port = ":".$_SERVER['SERVER_PORT'];
            }
            
            $base_url .= $_SERVER['SERVER_NAME'].$port.substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/'))."/";
            $this->base_url = $base_url;
        }
        return $this->base_url;
        
    }
    
    public function theme_url(){
        if(!empty($this->theme_url)){
            return $this->theme_url;
        }
        $config = $this->loadConfig('themes.php');
        $theme_url = $this->base_url."themes/".$config['theme_path']."/";
        $this->theme_url = $theme_url;
        return $this->theme_url;
    }
    public function css_url(){
        if(!empty($this->css_url)){
            return $this->css_url;
        }        
        $css_url = $this->theme_url."css/";
        $this->css_url = $css_url;
        return $css_url;
    }
    
    public function images_url(){
        if(!empty($this->images_url)){
            return $this->images_url;
        }
        $images_url = $this->theme_url."images/";
        $this->images_url = $images_url;
        return $images_url;
    }
    
    public function js_url(){
        if(!empty($this->js_url)){
            return $this->js_url;
        }
        $js_url = $this->theme_url."js/";
        $this->js_url = $js_url;
        return $js_url;
    }

    public function loadConfig($configFile){
        require_once $configFile;
        return $config;
    }
}

?>
